package cc.aiee.zalopay.model;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import cc.aiee.zalopay.core.pojo.ZalopayBaseModel;
import cc.aiee.zalopay.core.tool.ZalopayTool;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class ZalopayRefundModel extends ZalopayBaseModel {

	/**
	 * <li>提交退款要求时，商家必须生成商家自己的交易代码。</li>
	 * <li>格式：yymmdd_appid_xxxxxxxxxx</li>
	 */
	@NotBlank
	private String m_refund_id;

	/**
	 * <li>交易代码，要退款。</li>
	 * <li>ZaloPay的交易代码，从回调数据中检索</li>
	 */
	@NotBlank
	private String zp_trans_id;

	/**
	 * 用户退款金额
	 */
	@NotNull
	private Long amount;

	/**
	 * 退款时间（unix时间戳，以毫秒为单位）。
	 */
	@NotNull
	private Long timestamp;

	/**
	 * 退款原因
	 */
	private String description;

	public void setM_refund_id(String appId, String refundNo) {
		if (appId == null) {
			appId = super.getApp_id();
		}
		m_refund_id = ZalopayTool.getRefundId(appId, refundNo);
	}

}
